(function() {
    //得到元素
    var recommendLeftBtn = document.getElementById('recommend-btnleft');
    var recommendRightBtn = document.getElementById('recommend-btnright');
    var recommendImage = document.getElementById('recommend-img');
    var idx = 0;
    var lock = true;



    //点击左按钮
    recommendLeftBtn.onclick = function() {
            //上锁
            // 判断节流锁的状态，如果是关闭的，那么就什么都不做
            if (!lock) return;
            // 关锁

            lock = false;

            if (idx <= 5) {
                idx++;
                recommendImage.style.transition = 'transform .5s ease 0s';
                recommendImage.style.transform = 'translateX(' + -365 * idx + 'px)';
            } else {
                idx = 6;
            }
            // 开锁，动画结束之后开锁
            setTimeout(function() {
                lock = true;
            }, 500);

        }
        //点击右按钮
    recommendRightBtn.onclick = function() {
        //上锁
        //判断锁的状态
        if (!lock) return;
        //关锁
        lock = false;

        if (idx <= 6 && idx > 0) {
            idx--;
            recommendImage.style.transition = 'transform .5s ease 0s';
            recommendImage.style.transform = 'translateX(' + -365 * idx + 'px)';
        } else {
            idx = 0;
        }
        //开锁
        setTimeout(
            function() {
                lock = true;
            }, 500)

    }





})()